package ren.kane.phoenix.util.common;

import com.google.common.base.MoreObjects;

/**
 * 结果枚举类.
 *
 * @author renrk(1275) on 2018-07-17 10:31 AM
 **/
public enum ResultEnum {

    /**
     * 服务编码：200.
     * 模块编码：00-通用.
     */
    UNKNOW_ERROR("-1", "系统繁忙"),
    SUCCESS("0", "成功"),
    PARAM_NULL_ERROR("20000100", "请求参数不能为空"),
    PARAM_FORMAT_ERROR("20000101", "请求参数格式错误"),
    PARAM_OUT_OF_RANGE("20000102", "请求参数超出范围"),
    PARAM_CRON_ERROR("20000103", "CRON表达式格式错误"),
    SAVE_FAILED("20000500", "创建失败"),
    UPDATE_FAILED("20000501", "编辑失败"),
    DELETE_FAILED("20000502", "删除失败");

    // 错误编码
    private final String code;
    // 错误信息
    private final String msg;

    ResultEnum(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static String getCode(ResultEnum resultEnum) {
        return resultEnum.getCode();
    }

    public String getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    @Override
    public String toString() {
        return MoreObjects.toStringHelper(this)
            .add("code", code)
            .add("msg", msg)
            .toString();
    }
}
